<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        class Dequeue {
            constructor() {
                    this.item = [];
                }
                //前段插入
            addFront(element) {
                    this.item.unshift(element);
                }
                //后端插入
            addBack() {
                this.item.push();

            }
            removeFront() {
                return this.item.shift();
            }
            removeBack() {
                    return this.item.pop();
                }
                //toString()
            toString() {
                return this.item.toString();
            }
            peekFront() {
                if (this.item.length === 0) {
                    return undefined;
                } else {
                    return this.item[0];
                }

            }
            peekBack() {
                if (this.item.length === 0) {
                    return undefined;
                } else {
                    return this.item[length - 1];
                }
            }
        }
        const deque = new Dequeue();
        deque.addBack("john");
        deque.addBack("jack");
        deque.addBack("camila");
        console.log(deque.toString());
        console.log(deque.removeFront());
        console.log("前端" + deque.peekFront());
        console.log("后端" + deque.peekBack());
    </script>
</body>

</html>